package edu.kjxy.worker0322;

public class worker14 {

	public static void main(String[] args) {
		int row = 5;
		int[][] arr = new int[row][row];
		int cnt = 1;
		int left = 0, right = row - 1, top = 0, low = row - 1;
		while(cnt <= row * row) {
			//上
			for (int i = left; i <= right; i++) {
				arr[top][i] = cnt++;
			}
			top++;
			//右
			for(int i = top; i <= low; i++) {
				arr[i][right] = cnt++;
			}
			right--;
			if(top > low || left > right) {
				break;
			}
			//下
			for(int i = right; i >= left; i--) {
				arr[low][i] = cnt++;
			}
			low--;
			//左
			for(int i = low; i >= top; i--) {
				arr[i][left] = cnt++;
			}
			left++;
		}
		for (int i = 0; i < arr.length; i++) {
			for (int j = 0; j < arr[i].length; j++) {
				System.out.print(arr[i][j] + " ");
			}
			System.out.println();
		}
		
	}

}
